##   -*- autoconf -*-

AC_DEFUN(CHECK_GLIBVERSION,
[
 AC_MSG_CHECKING([Glib >= version 2.6])
 
 if `pkg-config --atleast-version=2.6 glib-2.0`; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(WITH_GLIB26, 1, [Define if Glib => 2.6])
 else
  AC_MSG_RESULT(no)
  AC_DEFINE(WITH_LIB26, 0, [Define if Glib => 2.6])
 fi
])


AC_DEFUN(CHECK_GTKVERSION,
[
 AC_MSG_CHECKING([GTK >= version 2.10])
 
 if `pkg-config --atleast-version=2.10 gtk+-2.0`; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(WITH_GTK210, 1, [Define if GTK => 2.10])
 else
  AC_MSG_RESULT(no)
  AC_DEFINE(WITH_GTK210, 0, [Define if GTK => 2.10])
 fi
])




dnl check Oracle version 
AC_DEFUN(CHECK_ORACLE,
[
  cflags_ora_save=$CFLAGS
  ldflags_ora_save=$LDFLAGS

  ora_libdir=
  ora_ldflags=

  AC_MSG_CHECKING(for ORACLE_HOME)
  if test "x$ORACLE_HOME" != "x"; then
    AC_MSG_RESULT($ORACLE_HOME)
  else
    AC_MSG_ERROR([not found, you must set ORACLE_HOME])
  fi


  AC_MSG_CHECKING(for Oracle client library)
  ora_libdir=`find $ORACLE_HOME -name 'libclntsh.so' 2>/dev/null | head -1`
  if test "x$ora_libdir" = "x"; then
    AC_MSG_ERROR([can't find libclntsh.so])
  else
    ora_libdir=`dirname $ora_libdir`
    AC_MSG_RESULT($ora_libdir)
  fi


  AC_MSG_CHECKING(if libnnz10 needed)
  need_nnz=`strings $ora_libdir/libclntsh.so |grep nnz10 | wc -l`
  if test "$need_nnz" = "1"; then
   ora_ldflags="-L$ora_libdir -lnnz10 -lclntsh"
   AC_MSG_RESULT([yes, $ora_ldflags])
  else
   ora_ldflags="-L$ora_libdir -lclntsh"
   AC_MSG_RESULT([no, $ora_ldflags])
  fi


  if expr `uname -s` = "SunOS" >/dev/null; then
   if test -x "/usr/bin/isainfo"; then
    if expr `isainfo -b` = "64" >/dev/null; then
     ora_cflags="-m64 $ora_cflags"
     ora_ldflags="-m64 $ora_ldflags"
    fi
   fi
  fi

  AC_MSG_CHECKING(for Oracle client headers)
  ora_incdir=`find $ORACLE_HOME -name 'oci.h' 2>/dev/null | head -1`
   if test "x$ora_incdir" = "x"; then
     AC_MSG_ERROR([can't find oci.h])
   else
     ora_incdir=`dirname $ora_incdir`
     dnl just to be safe append a couple standard directories
     ora_cflags="-I$ora_incdir -I$ORACLE_HOME/rdbms/demo -I$ORACLE_HOME/rdbms/public"
     AC_MSG_RESULT($ora_cflags)
   fi


  AC_MSG_CHECKING([that OCI compiles])
  CFLAGS="$CFLAGS $ora_cflags"
  LDFLAGS="$LDFLAGS $ora_ldflags"

  # Test OCI program
  AC_RUN_IFELSE([[
    #include <oci.h>
    OCIEnv             *envhp; 

    int main(int c, char **v) {
      OCIInitialize((ub4) OCI_OBJECT, (dvoid *)0,  (dvoid * (*)()) 0, (dvoid * (*)()) 0,  (void (*)()) 0 );
      OCIHandleAlloc((dvoid *) NULL, (dvoid **) &envhp, (ub4) OCI_HTYPE_ENV, 0, (dvoid **) 0);
      return 0;
    }
  ]], [compile_oracle=yes],
  [compile_oracle=no], )

  if test $compile_oracle = no; then
    AC_MSG_ERROR([Couldn't compile and run an OCI app])
  fi

  AC_MSG_RESULT(yes)

  CFLAGS=$cflags_ora_save
  AC_SUBST(CFLAGS, $ora_cflags)

  LDFLAGS=$ldflags_ora_save
  AC_SUBST(LDFLAGS, $ora_ldflags)

])

